#include<bits/stdc++.h>
using namespace std;
int t;
int n,m,l,vv;
int p[100005];
struct car
{
    int d,v,a;
}c[100005];
int main()
{
    std::ios::sync_with_stdio(false);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>n>>m>>l>>vv;
        int ans=0;
        for(int j=1;j<=n;j++) cin>>c[j].d>>c[j].v>>c[j].a;
        for(int j=1;j<=m;j++) cin>>p[j];
        for(int j=1;j<=n;j++){
                int minn=l;
                if(c[j].a==0) if(c[j].v>vv&&c[j].d<=p[m]) ans++;
                else if(c[j].a>0){
                    double v1=sqrt(2.0*(l-c[j].d)*c[j].a+c[j].v*c[j].v);
                    if(v1>vv){
                        double s=(vv*vv-c[j].v*c[j].v)/2.0/c[j].a;
                        if(s<=p[m]) ans++;
                    }
                }
        }
        cout<<ans<<" ";
        ans==0 ? cout<<m : cout<<m-1;
    }
    return 0;
}
